package com.ss.web.tagmark.utils;

import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import com.ss.web.tagmark.entity.User;

public class AuthContext {

	public static User getCurUser() {
		Authentication auth = SecurityContextHolder.getContext().getAuthentication();
		if (auth != null) {
			return (User) auth.getPrincipal();
		}
		return null;
	}

	public static String getCurFullname() {
		User u = getCurUser();
		if (u == null) {
			return "";
		}
		return u.getFullname();
	}

	public static boolean isLogin() {
		Authentication auth = SecurityContextHolder.getContext().getAuthentication();
		if (auth != null && auth.isAuthenticated() && (!(auth instanceof AnonymousAuthenticationToken))) {
			return true;
		}
		return false;
	}

}
